Skip to content

[PR] fix(egress): strip rendered acp tag before probe divergence compare - #8318

Open
sx4im wants to merge 2 commits into
ranxianglei:masterfrom
sx4im:fix-8316-egress-probe-tag-strip
Open

sx4im wants to merge 2 commits into
ranxianglei:masterfrom
sx4im:fix-8316-egress-probe-tag-strip

Conversation

@sx4im

@sx4im sx4im commented Dec 5, 2026

Copy link
Copy Markdown
Contributor

What broke

With egress on, every id-carrying plugin session logged a divergence warning every round, even when the client changed nothing. The probe compared server rows, which hold kernel output with the rendered <acp ...>mNNNNN</acp> tag ahead of the body, against the client's untagged text. The tag alone made every sampled row count as diverged, so a real divergence was indistinguishable from the noise.

What changed

egressAuthorityProbe strips the leading rendered acp tag from the server row text before the length and exact-text compare. The body compare is unchanged, so a real edit under a stable id still logs.

How verified

  • New regression test: tagged server rows against identical untagged client rows stay quiet, and a real body edit still warns. The test failed before the fix and passes after.
  • tests/egress-authority-ladder.test.ts: 8/8 pass.
  • npm run typecheck: clean.

Fixes #8316

@ranxianglei ranxianglei changed the title fix(egress): strip rendered acp tag before probe divergence compare [PR] fix(egress): strip rendered acp tag before probe divergence compare Dec 5, 2026
…glei#8316)

Zero behavior change — the pattern is byte-identical to the inline
literal it replaces (verified against the real tag shapes the kernel
emits, with and without time=). KDD ranxianglei#2 requires angle brackets in ACP
tag sequences to be hex-escaped in source files, because content
sanitizers upstream of git push mangle literal tags; kernel/src/ccr.ts
already uses this exact construction for its own LEADING_TAG_RE.

Extracted to a named module constant so the escape stays readable.
@ranxianglei

ranxianglei commented Dec 5, 2026 •

Copy link
Copy Markdown
Owner

🤖 Powered by ework · qwen4-35b-a3b

[bot] 🏷 Reviewed PR #8318 (fixes #8316) — the fix is correct, well-tested, and merge-ready pending CI green. I did a code-level review (root cause, regex, test, regression surface) plus CI; I did not run the full suite locally (that's CI's job per repo discipline).

Root cause confirmed. Egress table rows store kernel output with the rendered <acp …>mNNNNN</acp> tag ahead of the body. egressAuthorityProbe (src/server/egress-lane-io.ts) compared that tagged text against the client's untagged resend on contentType + length + exact text, so the tag alone made every sampled row count as diverged → a false warn every round, real drift indistinguishable from noise.

Fix is correct and minimal. It strips the leading rendered tag from the server row before the compare: LEADING_ACP_TAG_RE = /^\x3cacp\b[^>]*>m\d+\x3c\/acp>\n?/ (hex-escaped per KDD #2, same construction as the kernel's LEADING_TAG_RE). Body compare unchanged, so a real edit under a stable id still logs. Traced the regex against the kernel output format — strips cleanly, leaves the body intact.

On reusing the kernel's stripLeadingTag (kernel/src/ccr.ts:174): it's exported from ccr.ts but not re-exported from the kernel's public index.ts, and the package exports map exposes no deep ccr path — so the host can't import it cleanly. The PR's local regex is the justified choice, not a DRY miss. (If reuse is ever wanted, exporting it from the kernel index would be a gated kernel change.)

Test has teeth. New case (tests/egress-authority-ladder.test.ts:124) asserts both directions — tagged server rows vs identical untagged client rows stay quiet (logs.length === 0), and a real body edit still warns (logs.length === 1). It would fail before the fix. File now has 8 tests, matching the PR's "8/8 pass".

No regression surface. The strip only affects the probe's log-compare; recorded bytes, served bytes, and the flow are untouched. The probe is non-fatal (server bytes win) regardless.

CI (head e24cbcb): 0 real failures — 24 success, 23 skipped, 6 test shards still running (none failing); static-gates (typecheck) green. (The 47 "cancelled" rows are a superseded earlier run on the same head.)

Two notes for the owner (non-blocking):

  1. Issue egress 开启时,每个带 id 的插件会话每轮都报「客户端与服务端内容不一致」(其实谁都没改),真出问题时也分不出来 #8316 framed the fix as "二选一, owner 定" (minimal strip vs. store-untagged-bytes). This PR takes the minimal option, which fully resolves the reported log-noise symptom. The thorough option (store untagged bodies, render tags on egress — also drops the render-time time= from stored bytes) is a larger storage-format change; if the owner wants it, it should be a separate gated piece of work.
  2. The new test string uses a literal <acp …> tag. KDD fix: address all code review findings (condense, routing, session-id, dead code) #2 prefers hex escapes, but literal tags in test data are an established convention here (62 existing occurrences) and the load-bearing regex is hex-escaped — consistent with precedent, not a defect.

Verdict: code correct and merge-ready; the only gates are CI finishing green (6 test lanes running, none failing) and human review/merge (I don't merge).


结构化八问

  1. 是什么问题:egress 探针把「服务端行(正文前带渲染 acp 标签)」与「客户端行(无标签)」直接比对,标签本身让每行都判为 diverged → 每轮一条假 warn,真漂移淹没在噪音里。
  2. 什么原因导致的:服务端 egress 表存的是内核输出,正文前带渲染好的 <acp tokens type time>mNNNNN</acp>\n;客户端重发的是无标签原文。探针比 contentType + 长度 + 全文,标签让长度与全文必然不等。
  3. 影响范围与严重程度:所有开 egress、带 id 的插件会话,每轮一条假 divergence warn(四条 wire 均复现)。后果是日志噪音 + 真漂移无法区分(可观测性退化);探针非致命(服务端字节始终赢),不影响功能。严重度:中等(日志/排障误导),非 p1。
  4. 怎么修复的:在 egressAuthorityProbe 比对前剥掉服务端行开头的渲染 acp 标签(正则 ^\x3cacp\b[^>]*>m\d+\x3c/acp>\n?,按 KDD fix: address all code review findings (condense, routing, session-id, dead code) #2 十六进制转义)。正文比对不变,真改动仍会 warn。
  5. 是否有回归问题:无。剥离只影响探针的「记日志比对」,不碰记录字节/出站字节/flow;真 divergence 仍能检出(测试双向断言钉住)。
  6. 是否破坏缓存:不涉及。探针不触碰缓存;剥离只在比对处。
  7. 是否改了设计方向:否。在探针层做最小修复,符合现有 egress authority 设计(服务端为唯一内容权威)。
  8. 是否引入了新的配置:否。

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working p2 scope/storage

Projects

None yet

Development

Successfully merging this pull request may close these issues.

egress 开启时,每个带 id 的插件会话每轮都报「客户端与服务端内容不一致」(其实谁都没改),真出问题时也分不出来

2 participants